#ifndef RECT_H
#define RECT_H

#include "Vector2.h"

namespace Cvekas {

/// Rectangle
struct Rect
{
	/// Constructor
	Rect() : x(0), y(0), width(0), height(0) {};
	
	/// Constructor
	Rect(int x, int y, int width, int height) : x(x), y(y), width(width), height(height) {};
	
	/// Convert-to-WinApi-RECT operator
	operator RECT() const
	{
		RECT r;
		r.top = y;
		r.left = x;
		r.bottom = y + height;
		r.right = x + width;
		return r;
	}
	
	int x, y, width, height;
};

/// Rectangle, float coordinates
struct RectF
{
	/// Constructor
	RectF() : x(0.0f), y(0.0f), width(0.0f), height(0.0f) {}
	
	/// Constructor
	RectF(float x, float y, float width, float height) : x(x), y(y), width(width), height(height) {}

	RectF(const Vector2& top_left, const Vector2& size) 
		: x(top_left.x), y(top_left.y), width(size.x), height(size.y) {}
	
	/// Returns true if point is inside rectangle
	bool collidePoint(const Vector2& point)
	{
		if(point.x > x && point.x < (x + width))
			if(point.y > y && point.y < (y + height))
				return true;
		return false;
	}

	/// Returns top left point coordinates
	Vector2 topLeft()
	{
		return Vector2(x, y);
	}

	/// Returns width and height in Vector2
	Vector2 size()
	{
		return Vector2(abs(width), abs(height));
	}
 	
	/// Convert-to-WinApi-RECT operator
	operator RECT() const
	{
		RECT r;
		r.top = (int)y;
		r.left = (int)x;
		r.bottom = (int)(y + height);
		r.right = (int)(x + width);
		return r;
	}
	
	float x, y, width, height;
};

} // namespace

#endif